﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraTab;
using DOAN.GUI.User_Control;
using DOAN.GUI.Form;

namespace DOAN.GUI
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
        }

        #region Tab Control
        private int indexPage;
        private bool KTITem(string tab)
        {
            for (int i = 0; i < this.xtraTabControl.TabPages.Count; i++)
            {
                if (this.xtraTabControl.TabPages[i].Text == tab)
                {
                    indexPage = i;
                    return false;
                }
            }
            return true;
        }
        private void AddTab(string title, string name)
        {
            if (name == "btnDSKhachHang")
            {
                ucDSKhachHang control = new ucDSKhachHang();
                control.Dock = DockStyle.Fill;
                control.Dock = System.Windows.Forms.DockStyle.Fill;
                XtraTabPage newPage = new XtraTabPage();
                newPage.Name = control.Name;
                newPage.Text = title;
                newPage.Controls.Add(control);
                xtraTabControl.TabPages.Add(newPage);
                indexPage = xtraTabControl.TabPages.IndexOf(newPage);
                xtraTabControl.SelectedTabPageIndex = indexPage;
            }
            if (name == "btnDSHopDong")
            {
                ucDSHopDong control = new ucDSHopDong();
                control.Dock = DockStyle.Fill;
                control.Dock = System.Windows.Forms.DockStyle.Fill;
                XtraTabPage newPage = new XtraTabPage();
                newPage.Name = control.Name;
                newPage.Text = title;
                newPage.Controls.Add(control);
                xtraTabControl.TabPages.Add(newPage);
                indexPage = xtraTabControl.TabPages.IndexOf(newPage);
                xtraTabControl.SelectedTabPageIndex = indexPage;
            }
            if (name == "btnDSGoiCuoc")
            {
                ucDSGoiCuoc control = new ucDSGoiCuoc();
                control.Dock = DockStyle.Fill;
                control.Dock = System.Windows.Forms.DockStyle.Fill;
                XtraTabPage newPage = new XtraTabPage();
                newPage.Name = control.Name;
                newPage.Text = title;
                newPage.Controls.Add(control);
                xtraTabControl.TabPages.Add(newPage);
                indexPage = xtraTabControl.TabPages.IndexOf(newPage);
                xtraTabControl.SelectedTabPageIndex = indexPage;
            }
            if (name == "btnDSKhuyenMai")
            {
                ucDSKhuyenMai control = new ucDSKhuyenMai();
                control.Dock = DockStyle.Fill;
                control.Dock = System.Windows.Forms.DockStyle.Fill;
                XtraTabPage newPage = new XtraTabPage();
                newPage.Name = control.Name;
                newPage.Text = title;
                newPage.Controls.Add(control);
                xtraTabControl.TabPages.Add(newPage);
                indexPage = xtraTabControl.TabPages.IndexOf(newPage);
                xtraTabControl.SelectedTabPageIndex = indexPage;
            }

        }
        private void btnDSKhachHang_ItemClick(object sender, ItemClickEventArgs e)
        {
            int _Check = 0;
            foreach (DevExpress.XtraTab.XtraTabPage tab in xtraTabControl.TabPages)
                if (tab.Text == "Danh Sách Khách Hàng")
                {
                    xtraTabControl.SelectedTabPage = tab;
                    _Check = 1;
                }
            if (_Check != 1)
                AddTab(btnDSKhachHang.Caption, btnDSKhachHang.Name);
        }

        private void btnDSHopDong_ItemClick(object sender, ItemClickEventArgs e)
        {
            int _Check = 0;
            foreach (DevExpress.XtraTab.XtraTabPage tab in xtraTabControl.TabPages)
                if (tab.Text == "Danh Sách Hợp Đồng")
                {
                    xtraTabControl.SelectedTabPage = tab;
                    _Check = 1;
                }
            if (_Check != 1)
                AddTab(btnDSHopDong.Caption, btnDSHopDong.Name);
        }

        private void btnDSKhuyenMai_ItemClick(object sender, ItemClickEventArgs e)
        {
            int _Check = 0;
            foreach (DevExpress.XtraTab.XtraTabPage tab in xtraTabControl.TabPages)
                if (tab.Text == "Danh Sách Khuyến Mãi")
                {
                    xtraTabControl.SelectedTabPage = tab;
                    _Check = 1;
                }
            if (_Check != 1)
                AddTab(btnDSKhuyenMai.Caption, btnDSKhuyenMai.Name);
        }

        private void btnDSGoiCuoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            int _Check = 0;
            foreach (DevExpress.XtraTab.XtraTabPage tab in xtraTabControl.TabPages)
                if (tab.Text == "Danh Sách Gói Cước")
                {
                    xtraTabControl.SelectedTabPage = tab;
                    _Check = 1;
                }
            if (_Check != 1)
                AddTab(btnDSGoiCuoc.Caption, btnDSGoiCuoc.Name);
        }

        private void xtraTabControl_CloseButtonClick(object sender, EventArgs e)
        {
            xtraTabControl.TabPages.Remove(xtraTabControl.SelectedTabPage);
            xtraTabControl.SelectedTabPageIndex = indexPage - 1;
        }
        #endregion


        private void btnQuyDinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmThayDoiQuiDinh frm = new frmThayDoiQuiDinh();
            frm.ShowDialog();
        }

        private void btnDSDinhMucCuoc_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmDSDinhMucCuoc frm = new frmDSDinhMucCuoc();
            frm.ShowDialog();
        }

        private void btnTinhTrangKH_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmThemTinhTrangHD frm = new frmThemTinhTrangHD();
            frm.ShowDialog();
        }

   
        
    }
}